<template>
  <el-form
    :inline="true"
    ref="fromdata"
    :model="fromdata"
    :rules="rules"
    label-position="right"
  >
    <el-row>
      <el-form-item
        label="预约提前预警(分钟):"
        prop="min"
      >
        <el-input
          clearable
          v-model.number="fromdata.dictValue"
        />
      </el-form-item>

    </el-row>
    <el-row>
      如果设置了预约提前预警，在客户预计到点前会根据分钟进行计算，如果符合了提前时间则会把符合的预约记录进行置顶并高亮展示。(这是为0不做限制)
    </el-row>
    <el-row>
      <el-col align="right">
        <el-button
          class="maringTop"
          type="primary"
          @click="onSubmit"
        >确定</el-button>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import { addDict, updateDict, dictSetValueByKey } from "@/api/after-sale/dictionary";
import { getDict, getStoreId, getServerDict } from "@/utils/index";
export default {
  data () {
    return {
      fromdata: {
        dictKey: "预约提前预警分钟数", //字典类别
        dictValue: "", //字典值
        storeId: getStoreId(), //门店id
      },
      rules: {
        dictValue: [
          {
            required: true,
            message: "请输入预约提前预警分钟数",
            trigger: "blur",
          },
        ],
      },
      dictKey: {},
      type: "",
    }
  },
  methods: {
    onSubmit () {
      this.$refs["fromdata"].validate((valid) => {
        if (valid) {
          this.saveData();
        } else {
          return false;
        }
      });
    },
    async saveData () {
      const { success } = await dictSetValueByKey(this.fromdata.dictKey, this.fromdata.dictValue);
      if (success) {
        this.$message({
          message: "操作成功",
          type: "success",
        });
        this.$emit("close", true);
      } else {
        this.$message.error("操作失败");
      }
    },
  },
  async created () {

    let data = await getServerDict('预约提前预警分钟数');
    this.fromdata.dictValue = data[0].dictValue
  },
}
</script>
<style lang="scss" scoped>
.maringTop {
  margin-top: 10px;
}
</style>